﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

/// <summary>
/// Extension methods for files and directories
/// </summary>
public static class FileExtensions
{
    /// <summary>
    /// Filters the files in a directory by multiple file extensions
    /// </summary>
    /// <param name="directoryInfo">The directory to search</param>
    /// <param name="extensions">The file extensions to be matched</param>
    /// <returns>IEnumerable FileInfo</returns>
    public static IEnumerable<FileInfo> GetFilesByExtensions(this DirectoryInfo directoryInfo, params string[] extensions) {
        var allowedExtensions = new HashSet<string>(extensions, StringComparer.OrdinalIgnoreCase);
        return directoryInfo.EnumerateFiles().Where(f => allowedExtensions.Contains(f.Extension));
    } 
}